package com.qf.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.qf.annotation.RequiresPermissionsDesc;
import com.qf.pojo.DtsBrand;
import com.qf.service.DtsBrandService;
import com.qf.util.ResponseUtil;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

/**
 * @author lixu
 */
@RestController
@RequestMapping("/admin/brand")
@CrossOrigin
public class BrandController {

    @Autowired
    private DtsBrandService dtsBrandService;

    /**
     * #### 品牌制造商
     *
     * ##### 2.2.2.1. 品牌制造商列表
     *
     * - 接口地址 : http://localhost:8083/admin/brand/list?page=1&limit=20&sort=add_time&order=desc
     *
     * - 下行数据 :
     */
    @RequiresPermissionsDesc(menu = {"商场管理","品牌制造商"},button = "查询")
    @RequiresPermissions(value = "admin:brand:list")
    @GetMapping("/list")
    public Object list(@RequestParam(defaultValue = "1") Integer page,
                       @RequestParam(defaultValue = "20") Integer limit,
                       String sort,String order,Integer id, String name){
        IPage<DtsBrand> iPage = dtsBrandService.findListByQuery(page,limit,sort,order,id,name);
        Map data = new HashMap<>();
        data.put("total", iPage.getTotal());
        data.put("items", iPage.getRecords());
        return ResponseUtil.ok(data);
    }

    /**
     * /create
     */
    @RequiresPermissions(value = "admin:brand:create")
    @RequiresPermissionsDesc(menu = {"商场管理","品牌制造商"},button = "添加")
    @PostMapping("/create")
    public Object create(@RequestBody DtsBrand dtsBrand){
        dtsBrand = dtsBrandService.create(dtsBrand);
        return ResponseUtil.ok(dtsBrand);
    }

    /**
     * #### 品牌制造商
     *
     * ##### 2.2.2.1. 品牌制造商更新
     *
     */
    @RequiresPermissionsDesc(menu = {"商场管理","品牌制造商"},button = "编辑")
    @RequiresPermissions(value = "admin:brand:update")
    @PostMapping("/update")
    public Object update(@RequestBody DtsBrand dtsBrand){
        dtsBrand = dtsBrandService.update(dtsBrand);
        return ResponseUtil.ok(dtsBrand);
    }

    /**
     * 品牌制造商delete
     */
    @RequiresPermissions(value = "admin:admin:delete")
    @RequiresPermissionsDesc(menu = {"商场管理","品牌制造商"},button = "删除")
    @PostMapping("/delete")
    public Object delete(@RequestBody DtsBrand dtsBrand){
        dtsBrand = dtsBrandService.delete(dtsBrand);
        return ResponseUtil.ok(dtsBrand);
    }

}
